//
// Created by 党清浩 on 2021/10/19.
//

#include<stdio.h>

#define TRUE 1
#define FALSE 0
#define M 100

typedef char TYPE;
//定义栈
typedef struct {
    TYPE elem[M];
    int top;
} SeqStack;

void InitStack(SeqStack *S);

int Push(SeqStack *S, TYPE X);

int Pop(SeqStack *S, TYPE *x);

int GetTop(SeqStack *S, TYPE *x);

int IsEmpty(SeqStack *S);

int Match(char ch, char ch1);

int BM(char *str);


int main() {
    char a[100];
    gets(a);
    int n;
    n = BM(&a);
    printf("%d\n", n);
    return 0;
}

//初始化顺序栈
void InitStack(SeqStack *S) {
    S->top = -1;
}

int IsEmpty(SeqStack *S) {
    if (S->top == -1)
        return TRUE;
    else return FALSE;
}

//顺序栈进栈
int Push(SeqStack *S, TYPE X) {
    if (S->top == M - 1)
        return (FALSE);
    S->top++;
    S->elem[S->top] = X;
    return (TRUE);
}

//顺序栈出栈
int Pop(SeqStack *S, TYPE *X) {
    if (S->top == -1)
        return (FALSE);
    else {
        *X = S->elem[S->top];
        S->top--;
        return (TRUE);
    }
}

int GetTop(SeqStack *S, TYPE *X) {
    if (S->top == -1)
        return (FALSE);
    else {
        *X = S->elem[S->top];
        return (TRUE);
    }
}

int Match(char ch1, char ch2) {
    if (ch1 == '(' && ch2 == ')' || ch1 == '[' && ch2 == ']' || ch1 == '{' && ch2 == '}')
        return TRUE;
    else return FALSE;
}

int BM(char *str) {
    SeqStack S;
    int i;
    char ch;
    InitStack(&S);
    for (i = 0; str[i] != '\0'; i++) {
        switch (str[i]) {
            case '(':
            case '[':
            case '{':
                Push(&S, str[i]);
                break;
            case ')':
            case ']':
            case '}':
                if (IsEmpty(&S)) {
                    //printf("\n右括号多余");
                    return 2;
                } else {
                    GetTop(&S, &ch);
                    if (Match(ch, str[i])) {
                        Pop(&S, &ch);
                    } else {
                        //printf("\n对应的左右括号不同类！");
                        return 3;
                    }
                }
        }//switch
    }//for
    if (IsEmpty(&S)) {
        //printf("\n括号匹配");
        return 4;
    } else {
        //   printf("\n左括号多余！");
        return 1;
    }
}